import uvicorn
from fastapi import FastAPI, Depends
from fastapi.responses import HTMLResponse
import logging

from api.main import api_router
from core.config import Settings, settings, get_settings
from core.logger_manager import logger, init_logging, LOG_LEVEL

from dependencies.asgi_correlation_id.asgi_correlation_id import CorrelationIdMiddleware

from data import *

app = FastAPI(on_startup=[init_logging(level=LOG_LEVEL.INFO)])

app.add_middleware(CorrelationIdMiddleware)

app.include_router(api_router, prefix='/api/%s' % settings.API_VERSION)

@app.get("/")
async def hello(settings: Settings=Depends(get_settings)):
    env = settings.ENV
    logger.error(env)
    ver = settings.API_VERSION
    logger.error(ver)
    return HTMLResponse(
        f"""<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Serverless Devs - Powered By Serverless Devs</title>
    <link href="https://example-static.oss-cn-beijing.aliyuncs.com/web-framework/style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="website">
    <div class="ri-t">
        <h1>Devsapp: {env}, {ver}</h1>
        <h2>这是一个 FastAPI 项目</h2>
        <span>自豪地通过Serverless Devs进行部署</span>
        <br/>
        <p>您也可以快速体验： <br/>
            • 下载Serverless Devs工具：npm install @serverless-devs/s<br/>
            • 初始化项目：s init start-fastapi-v3<br/>

            • 项目部署：s deploy<br/>
            <br/>
            Serverless Devs 钉钉交流群：33947367
        </p>
    </div>
</div>
</body>
</html>
"""
    )

from typing import Annotated

from fastapi.security import OAuth2PasswordBearer
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")


@app.get("/items/")
async def read_items(token: Annotated[str, Depends(oauth2_scheme)]):
    return {"token": token}




if __name__ == "__main__":


    uvicorn.run(app, host="0.0.0.0", port=9000)
